//# sourceURL=http://uMapApp/Module/EventAlert/EventAlert
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "../../UI/Layer"
    , "../../Earth/ViewPort"
    , "../StakeNum/StakeNum"
    , "../../Earth/ViewShed"
], function (
    mhjs,
    uMap,
    uEarth,
    Layer,
    ViewPort,
    StakeNum,
    ViewShed
) {

    function EventAlert(option) {
        var _this = this;
        option && _this.OptionToProperties(option);

        // {
        //     "handleUser"   : "",
        //     "handleMessage": "",
        //     "mailReceivers": "",
        //     "memo"         : "",
        //     "deviceCode"   : "1000021",
        //     "alarmCode"    : "{CAB6CEE3-43DC-7549-B37D-DD3F014A8289}",
        //     "deviceName"   : "49#星光球机",
        //     "alarmDate"    : "1657653746",
        //     "picture"      : "https://192.168.0.226:8926/219bb6ff-0bbb-11ec-a34b-6a548083bb98/20220713/1/dsf_215d3d27-0217-11ed-9d0a-dafd1741813e_51413518_52011414.jpg;https://192.168.0.226:8926/b86b8c68-0bd2-11ec-81b2-a2f39dad764d/20220713/1/dsf_a750fc61-0217-11ed-9d0a-dafd1741813e_21214280_21628964.jpg",
        //     "alarmGrade"   : "1",
        //     "alarmStatus"  : "1",
        //     "alarmType"    : "305",
        //     "alarmId"      : "31922",
        //     "handleStatus" : "0",
        //     "handleDate"   : "",
        //     "channelName"  : "49#星光球机",
        //     "pictureSize"  : "597896",
        //     "channelId"    : "1000021$1$0$0"
        // }

        _this.title = _this.alarmTypeO && _this.alarmTypeO.alarmTypeName || "未知告警";
        _this.searchKey = _this.title + " " + _this.deviceName;
        _this.sortKey = _this.stakeNum && _this.stakeNum.distance;

        _this.time = _this.alarmDate && new Date(Number(_this.alarmDate) * 1000).format("yyyy-MM-dd hh:mm:ss");


        if (_this.position) {

            _this.position = new uMap.Position(_this.position);

            _this.viewport = new ViewPort($.extend(
                {},
                {center: _this.position.value},
                _this.viewport || {}
            ));

            _this.layer = new Layer({
                "app"     : _this.app,
                "viewport": _this.viewport
            });

            _this.marker = new uMap.Entity({
                objectOption: {
                    position : _this.position,
                    billboard: new uMap.BillboardGraphic({
                        objectOption: {
                            image                   : _this.app.icons.getIconMarker(_this.icon),
                            verticalOrigin          : "BOTTOM",
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    }),
                    label    : new uMap.LabelGraphic({
                        objectOption: {
                            text                    : _this["名称"],
                            verticalOrigin          : "TOP",
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    })
                }
            });
            _this.layer.dataSources.entities.add(_this.marker.object);

            _this.marker.on("click", function () {
                _this.trigger("click");
            });
        }

    }

    var _class = EventAlert;

    mhjs.OptionToPropertiesInterface(_class);
    mhjs.EventInterface(_class);

    Object.defineProperties(_class.prototype, {
        "open"  : {
            value: function () {

                var _this = this;

                if (!this.isOpened) {

                    this.layer && this.layer.open();
                    this.camera && this.camera.open();

                    this.isOpened = true;
                    this.trigger("open");
                }
            }
        },
        "close" : {
            value: function () {
                if (this.isOpened) {
                    this.layer && this.layer.close();
                    this.camera && this.camera.close();
                    this.isOpened = false;
                    this.trigger("close");
                }
            }
        },
        "toggle": {
            value: function () {
                if (this.isOpened) {
                    this.close();
                } else {
                    this.open();
                }
            }
        },
        "active": {
            value: function (isActive) {
                var _this = this;

                isActive = (isActive === undefined) || Boolean(isActive);
                _this.isActive = _this.isActive === undefined ? false : _this.isActive;

                if (isActive !== _this.isActive) {

                    if (isActive) {

                        if (_this.layer) {
                            // _this.layer.active();
                            _this.marker.label.fillColor = new uMap.Color(["#ff0"]);
                            _this.marker.label.scale = 1.2;
                            _this.marker.billboard.image = _this.app.icons.getIconMarker(_this.icon, true);
                        }

                        _this.camera && this.camera.active();

                        _this.trigger("active");
                    } else {

                        if (_this.layer) {
                            _this.marker.label.fillColor = new uMap.Color(["#fff"]);
                            _this.marker.label.scale = 1;
                            _this.marker.billboard.image = _this.app.icons.getIconMarker(_this.icon);
                        }

                        _this.camera && this.camera.unActive();

                        _this.trigger("unActive");
                    }

                    _this.isActive = isActive;

                }

            }
        }
    });

    return _class;

});